﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using LifeInSharePoint.Blog.Business.DAL;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace LifeInSharePoint.Blog.Common.WebParts.LISPTemp
{
    [ToolboxItemAttribute(false)]
    public class LISPTemp : WebPart
    {
        private Label _msg;
        private TextBox _url;
        private Button _submit;

        protected override void CreateChildControls()
        {
            _msg = new Label();
            this.Controls.Add(_msg);
            List<Post> BlogPosts = new List<Post>();

            BlogPosts = Posts.getPostsListItemCollection();
            foreach (var blogPost in BlogPosts)
            {
                _msg.Text += blogPost.Title + "<br />";
            }

            //_url = new TextBox();
            //this.Controls.Add(_url);

            //_submit = new Button();
            //this.Controls.Add(_submit);
            //_submit.Text = "Find Where I Am used";
            //_submit.Click += new EventHandler(_submit_Click);
        }

        //void _submit_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        SPFile file = GetSPFile(_url.Text);
        //        SPLinkCollection _linkCollection = file.BackwardLinks;

        //        foreach (SPLink link in _linkCollection)
        //        {
        //            _msg.Text += link.Url + "<br />";
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        _msg.Text = "It broke : " + ex.Message;
        //        throw;
        //    }
        //}

        //protected SPFile GetSPFile(string url)
        //{
        //    using (SPSite site = new SPSite(url))
        //    {
        //        using (SPWeb web = site.OpenWeb())
        //        {
        //            SPFile file = web.GetFile(url);
        //            return file;
        //        }
        //    }
        //}
    }
}
